package com.cwrl.spider.protocol.lwm2m.util;

import cn.hutool.core.codec.Base64;
import org.eclipse.leshan.core.link.Link;
import org.eclipse.leshan.core.model.ResourceModel;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class LwM2mValueParseUtil {
    static public String toPrettyString(ResourceModel.Type type, Object value) {
        switch (type) {
            case OPAQUE:
                // We don't print OPAQUE value as this could be credentials one.
                // Not ideal but didn't find better way for now.
                return new String(Base64.decode((byte[]) value), StandardCharsets.UTF_8);
            case CORELINK:
                return Arrays.toString((Link[]) value);
            default:
                return value.toString();
        }
    }
}
